﻿using ED.Common.BaseModel;
using ED.IService;
using ED.Model.Response.Menu;
using Microsoft.AspNetCore.Mvc;

namespace ED.Admin.Controllers
{
    /// <summary>
    /// 菜单相关
    /// </summary>
    public class MenuController : CommonController
    {
        private readonly IMenuOperationService menuOperationService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="menuOperationService"></param>
        public MenuController(IMenuOperationService menuOperationService)
        {
            this.menuOperationService = menuOperationService;
        }
        /// <summary>
        /// 获取菜单
        /// </summary>
        /// <param name="menuReq"></param>
        /// <returns></returns>
        [HttpPost]
        public ResponseOutput<List<MenuRoot>> GetMenuList(MenuReq menuReq)
        {
            var res = menuOperationService.GetMenuList(menuReq);

            return res;
        }

        /// <summary>
        /// 菜单编辑
        /// </summary>
        /// <param name="menuReq"></param>
        /// <returns></returns>
        [HttpPost]
        public ResponseOutput MenuOperate(MenuReq menuReq)
        {
            return menuOperationService.UpdateOrInsert(menuReq);

        }

        /// <summary>
        /// 菜单删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public ResponseOutput MenuDelete(int id)
        {
            var res = menuOperationService.Delete(id);
            if (res.Item1)
            {
                return ResponseOutput.Ok(res.Item2);
            }
            else
            {
                return ResponseOutput.NotOk(res.Item2);
            }
        }
    }
}
